/** 
 ** Copyright (c) 2010 Ushahidi Inc
 ** All rights reserved
 ** Contact: team@ushahidi.com
 ** Website: http://www.ushahidi.com
 ** 
 ** GNU Lesser General Public License Usage
 ** This file may be used under the terms of the GNU Lesser
 ** General Public License version 3 as published by the Free Software
 ** Foundation and appearing in the file LICENSE.LGPL included in the
 ** packaging of this file. Please review the following information to
 ** ensure the GNU Lesser General Public License version 3 requirements
 ** will be met: http://www.gnu.org/licenses/lgpl.html.	
 **	
 **
 ** If you have questions regarding the use of this file, please contact
 ** Ushahidi developers at team@ushahidi.com.
 ** 
 **/

package com.ushahidi.android.app;

import org.json.JSONException;
import org.json.JSONObject;

import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.R;
import com.google.android.maps.GeoPoint;
import com.ushahidi.android.app.AroundMeMap.HighSensitiveMultiTimeDeviceLocationListener;
import com.ushahidi.android.app.AroundMeMap.LowSensitiveOneTimeDeviceLocationListener;
import com.ushahidi.android.app.checkin.CheckinActivity;
import com.ushahidi.android.app.checkin.FacebookCheckIn;
import com.ushahidi.android.app.checkin.NetworkServices;
import com.ushahidi.android.app.checkin.FacebookCheckIn.SampleAuthListener;
import com.ushahidi.android.app.checkin.FacebookCheckIn.SampleLogoutListener;
import com.ushahidi.android.app.util.Util;
import com.ushahidi.android.facebook.BaseRequestListener;
import com.ushahidi.android.facebook.LoginButton;
import com.ushahidi.android.facebook.SessionEvents;
import com.ushahidi.android.facebook.SessionStore;
import com.ushahidi.android.facebook.SessionEvents.AuthListener;
import com.ushahidi.android.facebook.SessionEvents.LogoutListener;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.TextView;

public class Ushahidi extends DashboardActivity
{
    /** Called when the activity is first created. */
	private static final int          DIALOG_CHOOSE_IMAGE_METHOD   = 2;
	
    private static final int ADD_INCIDENT          = Menu.FIRST + 1;

    private static final int LIST_INCIDENT         = Menu.FIRST + 2;

    private static final int INCIDENT_MAP          = Menu.FIRST + 3;

    private static final int SETTINGS              = Menu.FIRST + 4;

    private static final int ABOUT                 = Menu.FIRST + 5;

    private static final int SYNC                  = Menu.FIRST + 6;

    private static final int LIST_INCIDENTS        = 0;

    private static final int MAP_INCIDENTS         = 1;

    private static final int ADD_INCIDENTS         = 2;

    private static final int I_Provide             = 3;

    private static final int VIEW_SETTINGS         = 4;

    private static final int I_NEED                = 5;

    private static final int REQUEST_CODE_SETTINGS = 1;

    private static final int REQUEST_CODE_ABOUT    = 2;

    private static final int DIALOG_PROMPT         = 0;

    private static final int DIALOG_ERROR          = 1;

	private static final int CAMERA_PIC_REQUEST = 6;

    private Handler          mHandler;

    private Button           provideBtn;

    private Button           addBtn;

    private Button           settingsBtn;

    private Button           mapBtn;

    private Button           personFinderBtn;
    
    private TextView           userNameTextField;

    // private Button aboutBtn;

    private Button           needBtn;

    private String           dialogErrorMsg        = "An error occurred fetching the reports. "
	                                                   + "Make sure you have entered an Ushahidi instance.";

    private Bundle           bundle;

    private boolean          refreshState          = false;

    // Checkin specific variables and functions
    
    // facebook variables
	private Facebook mFacebook = new Facebook("392464624110234");
	
    private SharedPreferences mPrefs;
    
    private AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
    
    private LoginButton mLoginButton;
    
    private TextView mText;
    
    // geo location
    private static double    holder_latitude;

    private static double    holder_longitude;

    private static String    browser_location_url;

    private static String    mapapp_location_url;

    private static String    shareString;

    private static int       GPScount;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
	super.onCreate(savedInstanceState);
	setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	setContentView(R.layout.main);
	setTitleFromActivityLabel(R.id.title_text);
	mHandler = new Handler();
	bundle = new Bundle();

	// load settings
	UshahidiPref.loadSettings(this);
	Log.v("Oceanmaster", "domain in pref is:[" + UshahidiPref.domain + "]");
	// check if domain has been set
	/*
	 * if (UshahidiPref.domain.length() == 0 ||
	 * UshahidiPref.domain.equals("http://")) {
	 * mHandler.post(mDisplayPrompt); }
	 */
	provideBtn = (Button) findViewById(R.id.incident_list);
	addBtn = (Button) findViewById(R.id.incident_add);
	settingsBtn = (Button) findViewById(R.id.deployment_settings);
	mapBtn = (Button) findViewById(R.id.incident_map);
	needBtn = (Button) findViewById(R.id.deployment_search);
	personFinderBtn = (Button) findViewById(R.id.person_finder);
	userNameTextField= (TextView)findViewById(R.id.username_txtfild);
    mLoginButton = (LoginButton) findViewById(R.id.login);
    mText= (TextView) findViewById(R.id.username_txtfild);
    mText.setTextSize((float) 12.0);
	// aboutBtn = (Button) findViewById(R.id.deployment_about);

	initializeUI();
	initializeFacebookSession();
	if(UshahidiApplication.mDb.CheckLastUpdate(this))
	    RefreshReports();
    }
    public void initializeFacebookSession()
    {
        SessionStore.restore(mFacebook, this);
        SessionEvents.addAuthListener(new SampleAuthListener());
        SessionEvents.addLogoutListener(new SampleLogoutListener());
        mLoginButton.init(this, mFacebook);
        if(mFacebook.isSessionValid())
        {
        	mAsyncRunner.request("me", new SampleRequestListener());
        }
    }
    public void RefreshReports()
    {
	ReportsTask reportsTask = new ReportsTask();
	reportsTask.appContext = this;
	reportsTask.execute();
    }
    public void ClickCamera()
    {
    	showDialog(DIALOG_CHOOSE_IMAGE_METHOD);
    }
    @Override
    public void onRefreshReports(View v)
    {
    	RefreshReports();
    }
    @Override
    public void onConnectFacebook(View v)
    {
		Intent intent = new Intent(Ushahidi.this, FacebookCheckIn.class);
		startActivityForResult(intent, VIEW_SETTINGS);
		setResult(RESULT_OK);
    }
    @Override
    public void onClickCamera(View v)
    {
    	Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
		startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
		setResult(RESULT_OK);
		
		LayoutInflater inflater = (LayoutInflater)
	       this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    PopupWindow pw = new PopupWindow(
	       inflater.inflate(R.layout.use_camera, null, false), 
	       100, 
	       100, 
	       true);
	    // The code below assumes that the root container has an id called 'main'
	    pw.showAtLocation(this.findViewById(R.id.db1_root), Gravity.CENTER, 0, 0); 
    }
    @Override
    public void onResume()
    {
	initializeUI();
	super.onResume();
    }

    /**
     * Initializes some of the UI components and test
     */
    public void initializeUI()
    {
	UshahidiPref.loadSettings(this);
	// This is to temporarily disable reports stuff

	if (UshahidiPref.isCheckinEnabled == 1)
	{
	    addBtn.setText(getString(R.string.checkin_btn));
	    provideBtn.setText(getString(R.string.checkin_list));
	}
	else
	{
	    addBtn.setText(getString(R.string.incident_menu_add));
	    provideBtn.setText(getString(R.string.incident_list));
	}

	provideBtn.setOnClickListener(new View.OnClickListener()
	{
	    public void onClick(View v)
	    {

		// Intent intent = new Intent(Ushahidi.this,
		// IncidentsTab.class);
		Intent intent = new Intent(Ushahidi.this, IProvide.class);
		startActivityForResult(intent, I_Provide);
		setResult(RESULT_OK);

	    }
	});

	settingsBtn.setOnClickListener(new View.OnClickListener()
	{
	    public void onClick(View v)
	    {

		Intent intent = new Intent(Ushahidi.this, Settings.class);
		startActivityForResult(intent, VIEW_SETTINGS);
		setResult(RESULT_OK);
	    }
	});

	addBtn.setOnClickListener(new View.OnClickListener()
	{
	    public void onClick(View v)
	    {
		if (UshahidiPref.isCheckinEnabled == 1)
		{
		    NetworkServices.fileName = "";
		    Intent checkinActivityIntent = new Intent().setClass(
			    Ushahidi.this, CheckinActivity.class);
		    startActivity(checkinActivityIntent);
		    setResult(RESULT_OK);
		}
		else
		{
		    Intent intent = new Intent(Ushahidi.this, AddIncident.class);
		    startActivityForResult(intent, ADD_INCIDENTS);
		    setResult(RESULT_OK);
		}
	    }
	});

	needBtn.setOnClickListener(new View.OnClickListener()
	{

	    public void onClick(View v)
	    {
		// Intent intent = new
		// Intent(Ushahidi.this,DeploymentSearch.class);
		Intent intent = new Intent(Ushahidi.this, INEED_V2.class);
		startActivityForResult(intent, I_NEED);
		setResult(RESULT_OK);
	    }
	});

	/*
	 * aboutBtn.setOnClickListener(new View.OnClickListener() {
	 * 
	 * public void onClick(View v) { Intent launchIntent = new
	 * Intent(Ushahidi.this, About.class);
	 * startActivityForResult(launchIntent, REQUEST_CODE_ABOUT);
	 * setResult(RESULT_OK);
	 * 
	 * } });
	 */

	mapBtn.setOnClickListener(new View.OnClickListener()
	{

	    public void onClick(View v)
	    {
		bundle.putInt("tab_index", 1);
		Intent launchIntent = new Intent(Ushahidi.this,
		        IncidentsTab.class);
		launchIntent.putExtra("tab", bundle);
		startActivityForResult(launchIntent, MAP_INCIDENTS);
		setResult(RESULT_OK);
	    }
	});

	personFinderBtn.setOnClickListener(new View.OnClickListener()
	{

	    @Override
	    public void onClick(View v)
	    {
		// TODO: consider bringing in shortlink to session
		UshahidiPref.loadSettings(Ushahidi.this);
		readyLocationService();// make sure current location and pick
				       // right
		GPScount = 1;
		// detail level
		// final String reportUrl = UshahidiPref.domain +
		// "/reports/view/" + id;

		// final String shareUrl ="geo:latitude,longitude?z=zoom";
	    }
	});
    }

    @Override
    protected Dialog onCreateDialog(int id)
    {
	switch (id)
	{
	    case DIALOG_PROMPT:
	    {
		AlertDialog dialog = (new AlertDialog.Builder(this)).create();
		dialog.setTitle("Ushahidi Setup");
		dialog.setMessage("Setup an ushahidi instance.");
		dialog.setButton2("Ok", new Dialog.OnClickListener()
		{
		    public void onClick(DialogInterface dialog, int which)
		    {
			Intent launchPreferencesIntent = new Intent().setClass(
			        Ushahidi.this, Settings.class);

			// Make it a subactivity so we know when it returns
			startActivityForResult(launchPreferencesIntent,
			        REQUEST_CODE_SETTINGS);
			dialog.dismiss();
		    }
		});
		dialog.setCancelable(false);
		return dialog;
	    }

	    case DIALOG_ERROR:
	    {
		AlertDialog dialog = (new AlertDialog.Builder(this)).create();
		dialog.setTitle(R.string.alert_dialog_error_title);
		dialog.setMessage(dialogErrorMsg);
		dialog.setButton2("Ok", new Dialog.OnClickListener()
		{
		    public void onClick(DialogInterface dialog, int which)
		    {

			Intent launchPreferencesIntent = new Intent(
			        Ushahidi.this, Settings.class);

			// Make it a subactivity so we know when it returns
			startActivityForResult(launchPreferencesIntent,
			        REQUEST_CODE_SETTINGS);

			dialog.dismiss();
		    }
		});
		dialog.setCancelable(false);
		return dialog;
	    }
	}
	return null;
    }

    final Runnable mDisplayPrompt      = new Runnable()
	                               {
	                                   public void run()
	                                   {
		                               showDialog(DIALOG_PROMPT);
	                                   }
	                               };

    final Runnable mDisplayErrorPrompt = new Runnable()
	                               {
	                                   public void run()
	                                   {
		                               showDialog(DIALOG_ERROR);
	                                   }
	                               };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
	super.onActivityResult(requestCode, resultCode, data);
	switch (requestCode)
	{
	    case REQUEST_CODE_SETTINGS:
		if (resultCode != RESULT_OK)
		{
		    break;
		}
		break;
	}
	 mFacebook.authorizeCallback(requestCode, resultCode, data);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
	    ContextMenu.ContextMenuInfo menuInfo)
    {
	populateMenu(menu);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
	populateMenu(menu);

	return (super.onCreateOptionsMenu(menu));
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
	// applyMenuChoice(item);

	return (applyMenuChoice(item) || super.onOptionsItemSelected(item));
    }

    @Override
    public boolean onContextItemSelected(MenuItem item)
    {

	return (applyMenuChoice(item) || super.onContextItemSelected(item));
    }

    private void updateRefreshStatus()
    {
	findViewById(R.id.refresh_report_btn).setVisibility(
	        refreshState ? View.GONE : View.VISIBLE);
	findViewById(R.id.title_refresh_progress).setVisibility(
	        refreshState ? View.VISIBLE : View.GONE);
    }

    private void populateMenu(Menu menu)
    {
	MenuItem i;

	if (UshahidiPref.isCheckinEnabled == 1)
	{
	    i = menu.add(Menu.NONE, ADD_INCIDENT, Menu.NONE,
		    R.string.checkin_btn);
	    i.setIcon(R.drawable.ushahidi_add);
	}
	else
	{
	    i = menu.add(Menu.NONE, ADD_INCIDENT, Menu.NONE,
		    R.string.incident_menu_add);
	    i.setIcon(R.drawable.ushahidi_add);
	}

	if (UshahidiPref.isCheckinEnabled == 1)
	{
	    i = menu.add(Menu.NONE, LIST_INCIDENT, Menu.NONE,
		    R.string.checkin_list);
	    i.setIcon(R.drawable.ushahidi_list);
	}
	else
	{
	    i = menu.add(Menu.NONE, LIST_INCIDENT, Menu.NONE,
		    R.string.incident_list);
	    i.setIcon(R.drawable.ushahidi_list);
	}

	i = menu.add(Menu.NONE, INCIDENT_MAP, Menu.NONE,
	        R.string.incident_menu_map);
	i.setIcon(R.drawable.ushahidi_map);

	i = menu.add(Menu.NONE, SYNC, Menu.NONE, R.string.menu_sync);
	i.setIcon(R.drawable.ushahidi_refresh);

	i = menu.add(Menu.NONE, SETTINGS, Menu.NONE, R.string.menu_settings);
	i.setIcon(R.drawable.ushahidi_settings);

	i = menu.add(Menu.NONE, ABOUT, Menu.NONE, R.string.menu_about);
	i.setIcon(R.drawable.ushahidi_about);

    }

    private boolean applyMenuChoice(MenuItem item)
    {
	// TODO: change menu names and functions

	Intent launchIntent;
	switch (item.getItemId())
	{
	    case LIST_INCIDENT:
		bundle.putInt("tab_index", 0);
		launchIntent = new Intent(Ushahidi.this, IProvide.class);
		launchIntent.putExtra("tab", bundle);
		startActivityForResult(launchIntent, LIST_INCIDENTS);
		setResult(RESULT_OK);
		return true;

	    case INCIDENT_MAP:
		bundle.putInt("tab_index", 1);
		launchIntent = new Intent(Ushahidi.this, IncidentsTab.class);
		launchIntent.putExtra("tab", bundle);
		startActivityForResult(launchIntent, MAP_INCIDENTS);
		setResult(RESULT_OK);
		return true;

	    case ADD_INCIDENT:
		if (UshahidiPref.isCheckinEnabled == 1)
		{
		    launchIntent = new Intent(Ushahidi.this,
			    CheckinActivity.class);
		    startActivityForResult(launchIntent, ADD_INCIDENTS);
		    setResult(RESULT_OK);
		}
		else
		{
		    launchIntent = new Intent(Ushahidi.this, AddIncident.class);
		    startActivityForResult(launchIntent, ADD_INCIDENTS);
		    setResult(RESULT_OK);
		}
		return true;

	    case ABOUT:
		launchIntent = new Intent(Ushahidi.this, About.class);
		startActivityForResult(launchIntent, REQUEST_CODE_ABOUT);
		setResult(RESULT_OK);
		return true;

	    case SETTINGS:
		launchIntent = new Intent().setClass(Ushahidi.this,
		        Settings.class);

		// Make it a subactivity so we know when it returns
		startActivityForResult(launchIntent, REQUEST_CODE_SETTINGS);
		setResult(RESULT_OK);
		return true;

	    case SYNC:
		ReportsTask reportsTask = new ReportsTask();
		reportsTask.appContext = this;
		reportsTask.execute();
		return true;

	}
	return false;
    }
    //face book class
    
    public class SampleAuthListener implements AuthListener {

        public void onAuthSucceed() {
        	mAsyncRunner.request("me", new SampleRequestListener());

        }

        public void onAuthFail(String error) {
            mText.setText("Login Failed: " + error);
        }
    }

    public class SampleLogoutListener implements LogoutListener {
        public void onLogoutBegin() {
            mText.setText("Logging out...");
        }

        public void onLogoutFinish() {
            mText.setText("You have logged out! ");
        }
    }
    public class SampleRequestListener extends BaseRequestListener {

        public void onComplete(final String response, final Object state) {
            try {
                // process the response here: executed in background thread
                Log.d("Facebook-Example", "Response: " + response.toString());
                JSONObject json = new JSONObject(response);
                final String name = json.getString("name");

                // then post the processed result back to the UI thread
                // if we do not do this, an runtime exception will be generated
                // e.g. "CalledFromWrongThreadException: Only the original
                // thread that created a view hierarchy can touch its views."
                Ushahidi.this.runOnUiThread(new Runnable() {
                    public void run() {
                    	
                        mText.setText("Hello there, " + name + "!");
                    }
                });
            } catch (JSONException e) {
                Log.w("Facebook-Example", "JSON Error in response");
            } catch (FacebookError e) {
                Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
            }
        }
    }
    // thread class
    private class ReportsTask extends AsyncTask<Void, Void, Integer>
    {

	protected Integer      status;

	private ProgressDialog dialog;

	protected Context      appContext;

	@Override
	protected void onPreExecute()
	{
	    refreshState = true;
	    updateRefreshStatus();
	    this.dialog = ProgressDialog.show(appContext,
		    getString(R.string.please_wait),
		    getString(R.string.fetching_new_reports), true);

	}

	@Override
	protected Integer doInBackground(Void... params)
	{
	    status = Util.processReports(appContext);
	    Util.checkForCheckin(appContext);
	    return status;
	}

	@Override
	protected void onPostExecute(Integer result)
	{
	    if (result == 4)
	    {
		Util.showToast(appContext, R.string.internet_connection);
	    }
	    else if (result == 3)
	    {
		Util.showToast(appContext, R.string.invalid_ushahidi_instance);
	    }
	    else if (result == 2)
	    {
		Util.showToast(appContext, R.string.could_not_fetch_reports);
	    }
	    else if (result == 1)
	    {
		Util.showToast(appContext, R.string.could_not_fetch_reports);
	    }
	    else
	    {
		Util.showToast(appContext,
		        R.string.reports_successfully_fetched);
	    }
	    this.dialog.cancel();
	    refreshState = false;
	    updateRefreshStatus();
	}

    }

    /********************
     * Geo Location related function OceanMaster
     ********************/
    LocationManager                                      manager;
    long                                                 updateTimeMsec = 1000;
    float                                                updateDistance = 0;
    LocationProvider                                     high;
    LocationProvider                                     low;
    private HighSensitiveMultiTimeDeviceLocationListener high_listener  = null;
    private LowSensitiveOneTimeDeviceLocationListener    low_listener   = null;

    private void registerHighOneTimeListener()
    {
	high_listener = new HighSensitiveMultiTimeDeviceLocationListener();
	manager.requestLocationUpdates(high.getName(), updateTimeMsec,
	        updateDistance, high_listener);
    }

    private void registerLowOneTimeListener()
    {
	low_listener = new LowSensitiveOneTimeDeviceLocationListener();
	manager.requestLocationUpdates(low.getName(), 100, updateDistance,
	        low_listener);
    }

    private void unregisterListeners()
    {
	if (high_listener != null)
	{
	    manager.removeUpdates(high_listener);
	    high_listener = null;
	}
	if (low_listener != null)
	{
	    manager.removeUpdates(low_listener);
	    low_listener = null;
	}
    }

    // Fetches the current location of the device.
    // create two different listeners, one for once, one for long
    // temporarily, periodical location service is not needed because
    // we are not following user
    private void readyLocationService()
    {
	Log.v("Oceanmaster", "Ready Location Service");
	// ===============================
	// ready one time location request
	// ===============================
	// listener = new OneTimeDeviceLocationListener();
	manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

	// get low and high accuracy provider
	// this is tempararily changed, due to simulation
	// low =
	// manager.getProvider(manager.getBestProvider(Util.createCoarseCriteria(),
	// true));
	// high =
	// manager.getProvider(manager.getBestProvider(Util.createFineCriteria(),
	// true));
	low = manager.getProvider(manager.NETWORK_PROVIDER);
	high = manager.getProvider(manager.GPS_PROVIDER);

	// imediately register 2 one time service to update location
	unregisterListeners();
	registerHighOneTimeListener();
	registerLowOneTimeListener();
    }

    public GeoPoint getPoint(double lat, double lon)
    {
	return (new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0)));
    }

    public void jumpToShare(Location location)
    {
	if (location != null)
	{
	    holder_latitude = location.getLatitude();
	    holder_longitude = location.getLongitude();
	    browser_location_url = "http://maps.google.com/maps?q="
		    + holder_latitude + "," + holder_longitude;
	    // mapapp_location_url
	    // ="geo:"+holder_latitude+","+holder_longitude+"?z=15";
	    shareString = getString(R.string.share_template,
		    browser_location_url);
	    String shareSub = getString(R.string.share_subject);
	    if (GPScount > 0)
	    {
		GPScount--;
		final Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("text/plain");
		intent.putExtra(Intent.EXTRA_TEXT, shareString);
		intent.putExtra(Intent.EXTRA_SUBJECT, shareSub);
		startActivity(Intent.createChooser(intent,
		        getText(R.string.title_share)));
	    }
	}
    }

    // get the current location of the device/user
    public class LowSensitiveOneTimeDeviceLocationListener implements
	    LocationListener
    {
	LowSensitiveOneTimeDeviceLocationListener()
	{
	    super();
	    Log.v("Oceanmaster", "new OneTimeListener Created");
	}

	public void onLocationChanged(Location location)
	{
	    if (location != null)
	    {
		manager.removeUpdates(LowSensitiveOneTimeDeviceLocationListener.this);
		jumpToShare(location);
	    }
	}

	public void onProviderDisabled(String provider)
	{
	    // Util.showToast(AroundMeMap.this, R.string.location_not_found);
	    Log.v("Oceanmaster", "LocationProvider " + provider.toString()
		    + " Disabled");
	}

	public void onProviderEnabled(String provider)
	{
	    Log.v("Oceanmaster", "LocationProvider " + provider.toString()
		    + " Enabled");
	}

	public void onStatusChanged(String provider, int status, Bundle extras)
	{
	}
    }

    public class HighSensitiveMultiTimeDeviceLocationListener implements
	    LocationListener
    {
	HighSensitiveMultiTimeDeviceLocationListener()
	{
	    super();
	    Log.v("Oceanmaster", "new MultiTimeListener Created");
	}

	public void onLocationChanged(Location location)
	{
	    if (location != null)
	    {
		// GPSUpdated = true;
		manager.removeUpdates(HighSensitiveMultiTimeDeviceLocationListener.this);
		jumpToShare(location);
	    }
	}

	public void onProviderDisabled(String provider)
	{
	    Util.showToast(
		    Ushahidi.this,
		    "GPS service is disabled due to Configuration or Low signal strength, please check your setting or go near the window.");
	    Log.v("Oceanmaster", "LocationProvider " + provider.toString()
		    + " Disabled");
	}

	public void onProviderEnabled(String provider)
	{
	    Util.showToast(Ushahidi.this, "GPS service recover.");
	    Log.v("Oceanmaster", "LocationProvider " + provider.toString()
		    + " Enabled");
	}

	public void onStatusChanged(String provider, int status, Bundle extras)
	{

	}
    }

}
